﻿using System;

namespace Com.Lancetinc.Evs.Communications
{
    /// <summary>
    /// 上位机和下位机的连接
    /// </summary>
    public interface IConnection
    {
        event EventHandler<PacketReceivedEventArgs> PacketReceived;

        /// <summary>
        /// 最后一次收到数据的时间
        /// </summary>
        DateTime LastReceivedDataTime { get; }

        /// <summary>
        /// 当前使用的端口名称
        /// </summary>
        string PortName { get; }

        /// <summary>
        /// 发送数据包
        /// </summary>
        /// <param name="packet">请求的数据包</param>
        void Send(Packet packet);

        /// <summary>
        /// 打开连接
        /// </summary>
        /// <param name="address">串口的场合为端口名称</param>
        void Connect(string address);

        /// <summary>
        /// 关闭连接
        /// </summary>
        void Close();

        /// <summary>
        /// 重新连接
        /// </summary>
        void Reconnect();

        /// <summary>
        /// 已连接？
        /// </summary>
        bool IsConnected { get; }
    }
}
